<?php 
/**
 * eBay Label Printing Program CMS Database Table Class 
 * this is a Db Table Class , It stores website documents
 * @package  eBayLabelPrinter
 * @category Models/DbTable
 * @author   Norman Dong <norman.dong@hotmail.com>
 * @version  Initial
 * @copyright LeadCasket.com
 * @link     www.leadcasket.com
 * @license  Commercial
 */
 class Model_DbTable_Cms_Article extends Zend_Db_Table_Abstract 
{
	/**
	 * @var string Class Table Name
	 */
	protected $_name = 'article'; 
	/**
	 * Insert New Article Function
	 * At Backoffice , Insert New article 
	 * @param str $articleTitle 
	 * @param datetime $articleDate  	 
	 * @param int $articlePosition  The list position of article in same category
	 * @param bool $articleFrontpage  if show this article in front page
	 * @param int $articleSection
	 * @param int $articleCategory 
	 * @param str $articleContent
	 * @return void  Nothing Return at the moment
	 */
	public function addArticle($articleTitle,$articleDate,$articlePosition,$articleFrontpage,$articleSection,$articleCategory,$articleContent){
		$data = array(
				'title_article' => $articleTitle,
				'date_article' => $articleDate,
				'position_article' => $articlePosition,
				'frontpage_article' => $articleFrontpage,
				'section_article' => $articleSection,
				'category_article' => $articleCategory,
				'content_article' => $articleContent,
				);
		$this->insert($data);
		}
		/**
		 * Update Article Content Function
		 * At Backoffice , Modify article
		 * @param int $articleID
		 * @param str $articleTitle
		 * @param datetime $articleDate
		 * @param int $articlePosition  The list position of article in same category
		 * @param bool $articleFrontpage  if show this article in front page
		 * @param int $articleSection
		 * @param int $articleCategory
		 * @param str $articleContent
		 * @return void  Nothing Return at the moment
		 */		
	public function updateArticle($articleID,$articleTitle,$articleDate,$articlePosition,$articleFrontpage,$articleSection,$articleCategory,$articleContent){
		$data = array(
				'title_article' => $articleTitle,
				'date_article' => $articleDate,
				'position_article' => $articlePosition,
				'frontpage_article' => $articleFrontpage,
				'section_article' => $articleSection,
				'category_article' => $articleCategory,
				'content_article' => $articleContent,
				);
		$this->update($data,'id_article ='.$articleID);
		}		
	public function deleteArticle($articleID){
		$this->delete('id_article =' . $articleID);
		}
	
	public function listArticleBySection($sectionID){
		$order = new Zend_Db_Expr('`position_article`');
		$rows = $this->fetchAll('`section_article` ='.(int)$sectionID,$order);
		if(empty($rows)){
			return false;
		}
		return $rows->toArray();
		}	
	public function listArticleByCategory($categoryID){
		$order = new Zend_Db_Expr('`position_article`');
		$rows = $this->fetchAll('`category_article` ='.(int)$categoryID,$order);
		if(empty($rows)){
			return false;
		}
		return $rows->toArray();		
		}
		/**
		 * Get Seller Group By ID
		 * Not decide what to do Yet
		 * @param int $idSeller  The Seller ID
		 * @return array  Not decide what to return
		 */
	public function getArticle($articleID){
		$row = $this->fetchRow('`id_article`='.(int)$articleID);			
		if(!$row){	
				return false;
		}
		return $row->toArray();
	}
	public function listArticle(){
		$order = new Zend_Db_Expr('`id_article`');
		$rows = $this->fetchAll('1',$order);
		if(empty($rows)){
			return false;
		}
		return $rows->toArray();		
	}					
}
?>